﻿using Acme.BookStore.AcmeModel;
using Acme.BookStore.Log;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace Acme.BookStore
{
    public class LogsServer :
        CrudAppService<
            LogsInfo, //The Book entity
            LogsInfoDto, //Used to show books
            Guid, //Primary key of the book entity
            PagedAndSortedResultRequestDto, //Used for paging/sorting
            LogsInfos>, //Used to create/update a book
        ILogsInfo //implement the IBookAppService
    {
        public IRepository<LogsInfo, Guid> _Logs;
        public LogsServer(IRepository<LogsInfo, Guid> Logs)
            : base(Logs)
        {
            _Logs = Logs;
        }
        [Route("日志管理显示")]
        /// <summary>
        /// 日志管理
        /// </summary>
        /// <returns></returns>
        //日志管理显示
        public List<LogsInfoDto> GetShow()
        {
            var str = (from a in _Logs
                       select new LogsInfoDto
                       {
                           Id = a.Id,
                           NlogTreay = a.NlogTreay,
                           NlogPsuin = a.NlogPsuin,
                           NlogMsg = a.NlogMsg,
                           NlogTime = a.NlogTime
                       }).ToList();
            return str;
        }
        [Route("日志管理添加")]
        [HttpPost]
        //日志管理添加
        public async Task<int> GetAdd(LogsInfos m)
        {
            LogsInfo str = ObjectMapper.Map<LogsInfos, LogsInfo>(m);
            await _Logs.InsertAsync(str);
            return 1;
        }
    }
}
